﻿using System.Windows;
using System.Windows.Input;
using MDCAdminTool.Reports;

namespace MDCAdminTool.Commands
{
    public class ClusterSize : AddCartTabCommandBinding
    {
        public ClusterSize()
        {
            Command    = Application.Current.Resources["ClusterSize"] as ICommand;
        }

        protected override void OnCanExecute( object sender , CanExecuteRoutedEventArgs e )
        {
            e.CanExecute = true;
        }
        protected override void OnExecuted( object sender , ExecutedRoutedEventArgs e )
        {
            var cache = e.Parameter as CacheHost;
            if ( cache == null )
            {
                var clusters = Application.Current.Properties["Clusters"] as Clusters;

                if ( clusters != null && clusters[0] != null ) 
                    cache = clusters[0].Hosts[0];
            }
            if ( cache != null )
            {
                foreach (var c in cache.Cluster.Hosts )
                {
                    c.LoadStatistics();
                }

                AddNewTab( "Cluster Size Report" , typeof(ClusterSizeChart ),  cache  );
            }
        }
    }
}